package clinica;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import java.awt.Font;
import javax.swing.JRadioButton;
import javax.swing.JButton;
import org.eclipse.wb.swing.FocusTraversalOnArray;
import java.awt.Component;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class CadAnimal extends JFrame {

	private JPanel contentPane;
	private JTextField txtNome;
	private JTextField txtRaca;
	private JTextField txtPeso;
	private JTextField txtIdade;
	private JTextField txtEspecie;
	private JRadioButton rdbtnMacho;
	private JRadioButton rdbtnFemea;
	private JButton btnSalvar;
	private JButton btnCancelar;
	private JLabel lblIdAnimal;
	private JLabel lblId;
	private int id=1;
	
	private String sexo;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					CadAnimal frame = new CadAnimal();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public CadAnimal() {
		addWindowListener(new WindowAdapter() {
		
			public void windowActivated(WindowEvent e) {
				lblId.setText(String.valueOf(id));
			}
		});
		
	
		
		setTitle("Cadastro De Animal");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 482, 614);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		txtNome = new JTextField();
		txtNome.setBounds(10, 122, 279, 20);
		contentPane.add(txtNome);
		txtNome.setColumns(10);
		
		JLabel lblCadastroDeAnimais = new JLabel("Cadastro de Animais");
		lblCadastroDeAnimais.setFont(new Font("Tahoma", Font.PLAIN, 17));
		lblCadastroDeAnimais.setBounds(150, 25, 153, 21);
		contentPane.add(lblCadastroDeAnimais);
		
		JLabel lblNomeDoAnimal = new JLabel("Nome Do Animal");
		lblNomeDoAnimal.setBounds(10, 97, 266, 14);
		contentPane.add(lblNomeDoAnimal);
		
		JLabel lblRacaDoAnimal = new JLabel("Ra\u00E7a Do Animal");
		lblRacaDoAnimal.setBounds(10, 172, 191, 14);
		contentPane.add(lblRacaDoAnimal);
		
		txtRaca = new JTextField();
		txtRaca.setColumns(10);
		txtRaca.setBounds(10, 201, 279, 20);
		contentPane.add(txtRaca);
		
		JLabel lblPesoDoAnimal = new JLabel("Peso Do Animal");
		lblPesoDoAnimal.setBounds(10, 242, 138, 14);
		contentPane.add(lblPesoDoAnimal);
		
		txtPeso = new JTextField();
		txtPeso.setColumns(10);
		txtPeso.setBounds(10, 271, 279, 20);
		contentPane.add(txtPeso);
		
		JLabel lblIdadeDoAnimal = new JLabel("Idade Do Animal");
		lblIdadeDoAnimal.setBounds(10, 329, 191, 14);
		contentPane.add(lblIdadeDoAnimal);
		
		txtIdade = new JTextField();
		txtIdade.setColumns(10);
		txtIdade.setBounds(10, 358, 279, 20);
		contentPane.add(txtIdade);
		
		JLabel lblEspecieDoAnimal = new JLabel("Especie Do Animal");
		lblEspecieDoAnimal.setBounds(10, 404, 266, 14);
		contentPane.add(lblEspecieDoAnimal);
		
		txtEspecie = new JTextField();
		txtEspecie.setColumns(10);
		txtEspecie.setBounds(10, 433, 279, 20);
		contentPane.add(txtEspecie);
		
		JLabel lblSexoDoAnimal = new JLabel("Sexo Do Animal");
		lblSexoDoAnimal.setBounds(10, 466, 106, 14);
		contentPane.add(lblSexoDoAnimal);
		
		rdbtnMacho = new JRadioButton("Macho");
		rdbtnMacho.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				rdbtnMacho.setSelected(true);
				rdbtnFemea.setSelected(false);
				sexo="Macho";
			}
		});
		rdbtnMacho.setBounds(10, 497, 109, 23);
		contentPane.add(rdbtnMacho);
		
		rdbtnFemea = new JRadioButton("Femea");
		rdbtnFemea.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				rdbtnFemea.setSelected(true);
				rdbtnMacho.setSelected(false);
				sexo="Femea";				
			}
		});
		rdbtnFemea.setBounds(134, 497, 109, 23);
		contentPane.add(rdbtnFemea);
		
		btnSalvar = new JButton("Salvar");
		btnSalvar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CadCliente.acme.AddPet(
						id,
						txtNome.getText(),
						txtRaca.getText(),
						Double.valueOf(txtPeso.getText()),
						Integer.valueOf(txtIdade.getText()),
						txtEspecie.getText(),
						sexo);
				id++;
				
			   CadCliente.btnVisualizar.setEnabled(true);
			   
				txtNome.setText(null);
				txtRaca.setText(null);
				txtPeso.setText(null);
				txtIdade.setText(null);
				txtEspecie.setText(null);
				rdbtnFemea.setSelected(false);
				rdbtnMacho.setSelected(false);
				
				sexo=null;
								
				
				dispose();
			}
		});
		btnSalvar.setBounds(84, 553, 91, 23);
		contentPane.add(btnSalvar);
		
		btnCancelar = new JButton("Cancelar");
		btnCancelar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				txtNome.setText(null);
				txtRaca.setText(null);
				txtPeso.setText(null);
				txtIdade.setText(null);
				txtEspecie.setText(null);
				rdbtnFemea.setSelected(false);
				rdbtnMacho.setSelected(false);
				
				sexo=null;
				
				
				dispose();
			}
		});
		btnCancelar.setBounds(250, 553, 91, 23);
		contentPane.add(btnCancelar);
		
		lblIdAnimal = new JLabel("Id Animal");
		lblIdAnimal.setBounds(363, 32, 65, 14);
		contentPane.add(lblIdAnimal);
		
		lblId = new JLabel("");
		lblId.setBounds(418, 25, 46, 24);
		contentPane.add(lblId);
		setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{txtNome, txtRaca, txtPeso, txtIdade, txtEspecie, rdbtnMacho, rdbtnFemea, btnSalvar, btnCancelar}));
	}
}
